/**
 * Copyright (c) 2016,http://www.365wuliu.com/  All Rights Reserved.
 */
package com.cargo.base.messagebox;

import com.cargo.base.json.JsonUtils;
import com.wordnik.swagger.annotations.ApiModelProperty;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * MessageBox:普通的返回对象
 * 
 * @Project Name:cargo
 * @File Name:MessageBox.java
 * @Package Name:com.cargo.common.vo
 * @Creator:wizard
 * @Date:2016年4月14日下午12:58:11
 */
public class MessageBox {
	@ApiModelProperty(value = "调用结果 (1:成功 0:失败)")
	private String code;
	@ApiModelProperty(value = "返回消息")
	private String message;
	@ApiModelProperty(value = "验证结果")
	Map<String, String> validateMap;

	public MessageBox() {

	}

	public MessageBox(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public MessageBox(String code, String message, Map<String, String> validateMap) {
		this.code = code;
		this.message = message;
		this.validateMap = validateMap;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * 返回非验证类结果
	 * @param code
	 * @param message
	 * @return
	 */
	public static MessageBox build(String code, String message) {
		return new MessageBox(code, message);
	}

	/**
	 * 完全自定义的结果
	 * @param code
	 * @param message
	 * @param validateMap
	 * @return
	 */
	public static MessageBox build(String code, String message, Map<String, String> validateMap) {
		return new MessageBox(code, message, validateMap);
	}

	/**
	 * 只返回验证结果
	 * @param validateMap
	 * @return
	 */
	public static MessageBox build(Map<String, String> validateMap) {
		return new MessageBox(validateMap.get("returncode"), null, validateMap);
	}

	public Map<String, String> getValidateMap() {
		return validateMap;
	}

	public void setValidateMap(Map<String, String> validateMap) {
		this.validateMap = validateMap;
	}
	
	public static String mapToMessage(Map<String, String> validateMap){
		Map<String, String> tempMap = validateMap;
		if(tempMap!=null){
			if(tempMap.containsKey("returncode")){
				tempMap.remove("returncode");
			}
			if(tempMap!=null && tempMap.size()>0){
				return JsonUtils.toJson(tempMap).replaceAll("\"", "").replaceAll("\\{", "[").replaceAll("\\}", "]");
			}
		}
		return "";
	}
	public static void main(String[] args) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("张三", "dsfds");
		map.put("李四", "dsfds");
		System.out.println(mapToMessage(map));
	}
}
